﻿NAMFox.ns(function() { with (NAMFox) {

name("XPCOM Unit Tests");

//////////////////////////////////////////////
// Test Cases
//////////////////////////////////////////////

test("$() throws when no parameter is supplied", function() {
    expectError(function() { $(); }, "Error");
});

test("$() returns interface when @ sign not supplied", function() {
    var _interface = $("nfxIDictionary");
    ok(_interface, '$("nfxIDictionary") must be truthy.');
    
    try {
        ok(_interface.QueryInterface(Components.interfaces.nsIJSIID), "The iface variable must be an nsIJSIID reference.");
    }
    catch (e) {
        ok(false, '$("nfxIDictionary") does not support the QueryInterface function : ' + e);
    }
    
    equals("nfxIDictionary", _interface.name, '$("nfxIDictionary").name must be nfxIDictionary."');
});

test("$() returns class when parameter starts with @ sign", function () {
    var clazz = $("@namfox.neoseeker.com/dictionary;1");
    ok(clazz, '$("@namfox.neoseeker.com/dictionary;1") must be truthy.');
    ok(clazz.instance, '$("@namfox.neoseeker.com/dictionary;1") must support an instance() function.');
    ok(clazz.service, '$("@namfox.neoseeker.com/dictionary;1") must support a service() function.');
    
    var d = clazz.instance("nfxIDictionary");
    ok(d, '$("@namfox.neoseeker.com/dictionary;1").instance("nfxIDictionary") must be truthy.');
    ok(d.clear, 'The dictionary instance must support a clear() function.');
    ok(d.hasKey, 'The dictionary instance must support a hasKey() function.');
    ok(d.getKeys, 'The dictionary instance must support a getKeys() function.');
    ok(d.getValue, 'The dictionary instance must support a getValue() function.');
    ok(d.setValue, 'The dictionary instance must support a setValue() function.');
    
    var a = $("@namfox.neoseeker.com/ajax;1").service("nfxIAjax");
    ok(a, '$("@namfox.neoseeker.com/dictionary;1").service("nfxIAjax") must be truthy.');
    ok(a.get, 'The AJAX service must support a get() function.');
    ok(a.post, 'The AJAX service must support a post() function.');
});

}});